package com.fruit.web.vo.genl;

import java.util.List;



import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.fruit.service.IColorService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.Color;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existColor")
@SessionScoped
public class ExistColorBean implements java.io.Serializable {

	private SelectItem[] colorItems;

	public SelectItem[] getColorItems() {
		return colorItems;
	}

	public void setColorItems(SelectItem[] colorItems) {
		this.colorItems = colorItems;
	}
	public ExistColorBean() {
		
		IColorService<Color,Long> colorService = (IColorService<Color,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.COLOR_SERVICE_BEAN_NAME);
		colorService.setEntityClass(Color.class);
		colorService.setPKClass(Long.class);
		List<Color> colors = colorService.getAll("serialNumber",true);
		SelectItem[] tempColorItems = new SelectItem[colors.size()];
		//set select default 
		if (null != colors && !(colors.isEmpty())) {
			for (int i=0; i< tempColorItems.length; i++) {
				Color color = (Color) colors.get(i);
				String colorNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,color.getColorName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempColorItems[i] = new SelectItem(color.getColorId(),colorNameN18);
			}
		}
		this.setColorItems(tempColorItems);
	}
}
